Xbasic

SQL::ResultSetColumnNumber Method

Syntax

result as N = ColumnNumber(Name as C)

Arguments

NameCharacter

The name of the field in the selected table.

Returns

resultNumeric

Returns the number of the column. The first column is 1. If no column exists with the specified column name, ColumnNumber() will return 0.

Description

Get the number of the column named.

Discussion

The ColumnNumber() method returns the number of the named column. This function is usually used with the SQL::ResultSet Data() function, which uses column numbers to read data from a SQL::ResultSet.

Example

dim conn as SQL::Connection
dim args as SQL::Arguments
dim sql as C
sql = "select * from customers where country = :country"

args.set("country","Spain")

if .not. conn.open("::Name::AADemo-Northwind")
    ui_msg_box("Error", conn.CallResult.text)
    end
end if

if .not. conn.execute(sql,args)
    ui_msg_box("Error", conn.CallResult.text)
    conn.close()
    end
end if

if (conn.ResultSet.NextRow()) then
    dim col as n
    col = conn.ResultSet.ColumnNumber("City")

    ui_msg_box("SQL::ResultSet ColumnNumber()",  "Column Number for City is: " + col)
else
    ' No records retrieved
end if

conn.close()